class Character {
    constructor(name, profession, age) {
        this.name = name || this.generateChineseName();
        this.profession = profession;
        this.age = age || this.generateAge(profession);
        this.health = 100;
        
        // 需求系统
        this.needs = {
            hunger: 100,    // 饥饿度
            thirst: 100,     // 口渴度
            energy: 100,     // 精力
            happiness: 100   // 幸福感
        };
        
        // Debuff状态
        this.debuffs = {
            hungry: false,   // 饥饿debuff
            thirsty: false,  // 口渴debuff  
            sleepy: false,   // 困意debuff
            diarrhea: false  // 腹泻debuff
        };

        // 腹泻状态
        this.diarrhea = {
            active: false,
            duration: 0,
            startTime: null
        };
        
        // 物品栏（无上限）
        this.inventory = {
            materials: [],
            food: [],
            tools: [],
            money: this.getInitialMoney(profession)
        };
        
        // 工具耐久度记录
        this.toolDurability = {};
        
        // 家庭存储
        this.homeStorage = {
            food: [],
            water: 0,
        };
        
        // 位置和状态 - 初始位置为各自的家（工作地点）
        this.currentLocation = this.getHomeLocation();
        this.currentAction = '待机中';
        this.isMoving = false;
        this.isWorking = false;
        
        // 移动相关
        this.targetLocation = null;
        this.moveProgress = 0;
        this.moveDuration = 0;
        
        // 工作相关
        this.workProgress = 0;
        this.workDuration = 0;
        
        // 每日时间表
        this.dailySchedule = {
            wakeUpTime: 6,
            workStartTime: 8,
            lunchTime: 12,
            workEndTime: 17,
            sleepTime: 20
        };
        
        // 随机需求阈值（5%-30%）
        this.needsThreshold = {
            hunger: 0.05 + Math.random() * 0.25,
            thirst: 0.05 + Math.random() * 0.25,
            energy: 0.05 + Math.random() * 0.25
        };
        
        // 预估耗时（分钟）
        this.estimatedTime = {
            eat: 5 + Math.floor(Math.random() * 16),      // 5-20分钟
            drink: 2 + Math.floor(Math.random() * 6),     // 2-7分钟
            sleep: 30 + Math.floor(Math.random() * 31)    // 30-60分钟
        };
    }
    
    // 生成中式姓名
    generateChineseName() {
        const familyNames = ['李', '王', '张', '刘', '陈', '杨', '赵', '黄', '周', '吴', '徐', '孙', '马', '朱', '胡', '郭', '何', '高', '林', '郑'];
        const maleNames = ['伟', '强', '勇', '军', '杰', '磊', '超', '鹏', '明', '涛', '刚', '华', '平', '建', '文', '云', '龙', '金', '成', '亮'];
        const femaleNames = ['芳', '娜', '敏', '静', '秀', '英', '娟', '艳', '玲', '霞', '莉', '萍', '颖', '兰', '洁', '婷', '莹', '雪', '梅', '慧'];
        
        const familyName = familyNames[Math.floor(Math.random() * familyNames.length)];
        const isMale = Math.random() > 0.5;
        const givenName = isMale ? 
            maleNames[Math.floor(Math.random() * maleNames.length)] :
            femaleNames[Math.floor(Math.random() * femaleNames.length)];
            
        return familyName + givenName;
    }
    
    // 根据职业生成合适年龄
    generateAge(profession) {
        const ageRanges = {
            'MINER': { min: 25, max: 55 },          // 矿工
            'FARMER': { min: 30, max: 65 },         // 农民
            'BLACKSMITH': { min: 极35, max: 60 },     // 铁匠
            'CHE极F': { min: 25, max: 50 },           // 厨师
            'WARRIOR': { min: 20, max: 45 },        // 战士
            'MAGE': { min: 25, max: 50 },           // 法师
            'ARCHER': { min: 20, max: 40 },         // 弓手
            'PRIEST': { min: 30, max: 60 },         // 牧师
            'WATER_CARRIER': { min: 18, max: 35 },  // 挑水工
            'LUMBERJACK': { min: 25, max: 50 },     // 伐木工
            'HUNTER': { min: 22, max: 45 },        // 猎人
            'FISHERMAN': { min: 28, max: 55 },      // 渔民
            'HERDSMAN': { min: 30, max: 60 },       // 牧民
            'FRUIT_GROWER': { min: 25, max: 55 },   // 果农
            'MAYOR': { min: 45, max: 70 }           // 镇长
        };
        
        const range = ageRanges[profession] || { min: 20, max: 60 };
        return range.min + Math.floor(Math.random() * (range.max - range.min + 1));
    }
    
    // 获取家的位置（所有角色的家都在城镇内）
    getHomeLocation() {
        // 所有角色的家都在城镇内，使用职业名称作为家的标识
        return `${this.profession}_家`;
    }
    
    // 获取初始金钱（根据职业）
    getInitialMoney(profession) {
        const moneyRanges = {
            'MINER': { min: 50, max: 100 },
            'FARMER': { min: 30, max极: 80 },
            'BLACKSMITH': { min: 100, max: 200 },
            'CHEF': { min: 80, max: 150 },
            'WARRIOR': { min: 60, max: 120 },
            'MAGE': { min: 70, max: 130 },
            'ARCHER': { min: 50, max: 100 },
            'PRIEST': { min: 40, max: 90 },
            'WATER_CARRIER': { min: 20, max: 60 },
            'LUMBERJACK': { min: 40, max: 90 },
            'HUNTER': { min: 60, max: 120 },  // 猎人
            'FISHERMAN': { min: 35, max: 85 },
            'HERDSMAN': { min: 45, max: 95 },
            'FRUIT_GROWER': { min: 35, max: 85 },
            'MAYOR': { min: 200, max: 400 }
        };
        
        const range = moneyRanges[profession] || { min: 30, max: 100 };
        return range.min + Math.floor(Math.random() * (range.max - range.min + 1));
    }
    
    // 移动到指定位置
    moveTo(targetLocation) {
        const distance = this.calculateDistance(this.currentLocation, targetLocation);
        if (distance > 0) {
            this.targetLocation = targetLocation;
            this.moveDuration = distance * 5; // 1单位距离=5分钟（加速6倍）
            this.moveProgress = 0;
            this.isMoving = true;
            this.currentAction = `前往${targetLocation}`;
        } else {
            this.currentLocation = targetLocation;
            this.currentAction = '已到达目的地';
        }
    }
    
    // 计算两个位置之间的距离
    calculateDistance(from, to) {
        const distances = {
            '城镇广场': {
                '铁矿山': 6, '铜矿山': 8, '河滨': 3, '海滨': 4, '森林': 4,
                '农场': 5, '牧场': 4, '果林': 3, '魔域': 12
            },
            '魔域': {
                '魔兽山': 1, '鬼怪湖': 2, '火焰山': 3, '雪山': 2
            }
        };
        
        return distances[from]?.[to] || 0;
    }
    
    // 更新状态（每分钟调用）
    update(gameTime, timeMultiplier = 1) {
        const hour = gameTime.hour;
        const timeDelta = timeMultiplier; // 根据时间倍速调整
        
        // 需求消耗速率（12小时饥饿耗尽，6小时口渴耗尽，12小时精力耗尽）
        this.needs.hunger = Math.max(0, this.needs.hunger - (100 / (12 * 60)) * timeDelta);
        this.needs.thirst = Math.max(0, this.needs.thirst - (100 / (6 * 60)) * timeDelta);
        this.needs.energy = Math.max(0, this.needs.energy - (100 / (12 * 60)) * timeDelta);
        
        // 更新debuff状态
        this.updateDebuffs();
        
        // 应用debuff效果（降低幸福感）
        this.applyDebuffEffects(timeDelta);
        
        // 更新腹泻状态
        this.updateDiarrhea(timeDelta);
        
        // 生命值受需求影响
        if (this.needs.hunger < 20 || this.needs.thirst < 10 || this.needs.energy < 5) {
            this.health = Math.max(0, this.health - 0.2 * timeDelta);
        } else {
            this.health = Math.min(100, this.health + 0.1 * timeDelta);
        }
        
        // 更新移动状态
        if (this.isMoving) {
            this.moveProgress += timeDelta;
            if (this.moveProgress >= this.moveDuration) {
                this.currentLocation = this.targetLocation;
                this.isMoving = false;
                this.currentAction = '到达目的地';
            }
        }
        
        // 更新工作状态
        if (this.isWorking) {
            this.workProgress += timeDelta;
            if (this.workProgress >= this.workDuration) {
                this.completeWork();
            }
        }
        
        // 自动满足需求
        this.autoSatisfyNeeds();
    }
    
    // 更新debuff状态
    updateDebuffs() {
        // 触发debuff（需求低于30时）
        this.debuffs.hungry = this.needs.hunger < 30;
        this.debuffs.thirsty = this.needs.thirst < 30;
        this.debuffs.sleepy = this.needs.energy < 30;
        
        // 消除debuff（需求高于60时）
        if (this.needs.hunger > 60) this.debuffs.hungry = false;
        if (this.needs.thirst > 60) this.debuffs.thirsty = false;
        if (this.needs.energy > 60) this.debuffs.sleepy = false;
    }
    
    // 应用debuff效果
    applyDebuffEffects(timeDelta) {
        // 每个活跃的debuff每分钟降低5点幸福感
        let activeDebuffs = 0;
        if (this.debuffs.hungry) activeDebuffs++;
        if (this.debuffs.thirsty) activeDebuffs++;
        if (this.debuffs.sleepy) activeDebuffs++;
        if (this.debuffs.diarrhea) activeDebuffs++;
        
        if (activeDebuffs > 0) {
            this.needs.happiness = Math.max(0, this.needs.happiness - (5 * activeDebuffs * timeDelta));
        } else {
            // 没有debuff时缓慢恢复幸福感（每分钟恢复1点，直到100）
            this.needs.happiness = Math.min(100, this.needs.happiness + 1 * timeDelta);
        }
    }
    
    // 更新腹泻状态
    updateDiarrhea(timeDelta) {
        if (this.diarrhea.active) {
            // 腹泻效果：降低精力值和水满足度
            this.needs.energy = Math.max(0, this.needs.energy - 2 * timeDelta);
            this.needs.thirst = Math.max(0, this.needs.thirst - 3 * timeDelta);
            
            // 检查腹泻是否结束
            if (this.diarrhea.duration <= 0) {
                this.diarrhea.active = false;
                this.debuffs.diarrhea = false;
                this.currentAction = '腹泻症状已缓解';
            } else {
                // 减少剩余时间（每分钟减少1/60小时）
                this.diarrhea.duration -= timeDelta / 60;
            }
        }
    }
    
    // 自动满足需求
    autoSatisfyNeeds() {
        // 睡觉时间恢复精力（20:00-6:00）- 8小时恢复满精力
        const hour = new Date().getHours();
        if (hour >= 20 || hour < 6) {
            this.needs.energy = Math.min(100, this.needs.energy + (100 / (8 * 60)));
        }
        
        // 如果在睡觉中，持续恢复精力
        if (this.currentAction.includes('睡觉')) {
            this.needs.energy = Math.min(100, this.needs.energy + (100 / (8 * 60)));
        }
    }
    
    // 获取工作持续时间
    getWorkDuration() {
        const durations = {
            'MINER': 240,       // 4小时
            'FARMER': 360,      // 6小时
            'BLACKSMITH': 300,  // 5小时
            'CHEF': 240,        // 4小时
            'WARRIOR': 180,     // 3小时
            'MAGE': 极240,        // 4小时
            'ARCHER': 180,      // 3小时
            'PRIEST': 240,      // 4小时
            'WATER_CARRIER': 120, // 2小时
            'LUMBERJACK': 300,  // 5小时
            'HUNTER': 240,      // 4小时（猎人）
            'FISHERMAN': 240,   // 4小时
            'HERDSMAN': 360,    // 6小时
            'FRUIT_GROWER': 300 // 5小时
        };
        
        return durations[this.profession] || 240;
    }
    
    // 开始工作（支持多个工作地点和材料）
    startWork() {
        const profession = PROFESSIONS[this.profession];
        
        // 如果有多个工作地点，随机选择一个
        if (profession.workPlaces && profession.workPlaces.length > 0) {
            const randomWorkPlace = profession.workPlaces[Math.floor(Math.random() * profession.workPlaces.length)];
            
            // 如果不在工作地点，先移动到工作地点
            if (this.currentLocation !== randomWorkPlace) {
                this.moveTo(randomWorkPlace);
                this.currentAction = `前往${randomWorkPlace}工作`;
                return;
            }
        }
        
        this.workDuration = this.getWorkDuration();
        this.workProgress = 0;
        this.isWorking = true;
        this.currentAction = '工作中';
    }
    
    // 完成工作（根据职业定义和随机性设置产生产品）
    completeWork() {
        this.isWorking = false;
        this.currentAction = '工作完成';
        
        const profession = PROFESSIONS[this.profession];
        
        // 根据职业类型和随机性设置产生产品
        if (profession.materials && profession.materials.length > 0) {
            // 矿工类职业（非随机）：根据工作地点产生产品
            if (this.profession === 'MINER') {
                let producedMaterial = '铁矿石'; // 默认
                
                // 根据工作地点决定产出
                if (this.currentLocation === '铜矿山') {
                    producedMaterial = '铜矿石';
                } else if (this.currentLocation === '银矿山') {
                    producedMaterial = '银矿石';
                } else if (this.currentLocation === '金矿山') {
                    producedMaterial = '金矿石';
                }
                
                this.addToInventory(producedMaterial, 1 + Math.floor(Math.random() * 3));
            }
            // 铁匠类职业（非随机）：根据材料产生产品
            else if (this.profession === 'BLACKSMITH') {
                // 检查有什么材料，按价值优先级处理
                const materials = this.inventory.materials.filter(mat => 
                    ['铁矿石', '铜矿石', '银矿石', '金矿石'].includes(mat.name)
                ).sort((a, b) => ITEMS.find(i => i.name === b.name)?.price - ITEMS.find(i => i.name === a.name)?.price);
                
                if (materials.length > 0) {
                    const bestMaterial = materials[0].name;
                    let product = '铁剑';
                    
                    switch (bestMaterial) {
                        case '铜矿石': product = '铜剑'; break;
                        case '银矿石': product = '银饰'; break;
                        case '金矿石': product = '金饰'; break;
                    }
                    
                    this.addToInventory(product, 1);
                    this.removeFromInventory(bestMaterial, 1);
                }
            }
            // 厨师类职业（随机）：随机产生一种食物
            else if (this.profession === 'CHEF') {
                const availableMaterials = this.inventory.materials.filter(mat => 
                    ['猪肉', '牛肉', '羊肉', '鸡肉', '鸭肉', '鲈鱼', '草鱼', '鲤鱼', '鲅鱼', '鲫鱼', '鳕鱼', '苹果', '梨', '桃', '葡萄', '橙子', '香蕉'].includes(mat.name)
                );
                
                if (availableMaterials.length > 0) {
                    const randomMaterial = availableMaterials[Math.floor(Math.random() * availableMaterials.length)];
                    let product = '炖肉';
                    
                    // 根据材料类型决定产品
                    if (['鲈鱼', '草鱼', '鲤鱼', '鲅鱼', '鲫鱼', '鳕鱼'].includes(randomMaterial.name)) {
                        product = Math.random() > 0.5 ? '炖鱼' : '鱼干';
                    } else if (['苹果', '梨', '桃', '葡萄', '橙子', '香蕉'].includes(randomMaterial.name)) {
                        product = '蜜饯';
                    } else {
                        product = ['炖肉', '烤肉', '肉干'][Math.floor(Math.random() * 3)];
                    }
                    
                    this.addToInventory(product, 1);
                    this.removeFromInventory(randomMaterial.name, 1);
                }
            }
            // 渔民类职业（随机）：随机产生一种鱼
            else if (this.profession === 'FISHERMAN') {
                const randomFish = profession.materials[Math.floor(Math.random() * profession.materials.length)];
                this.addToInventory(randomFish, 1 + Math.floor(Math.random() * 2));
            }
            // 牧民类职业（随机）：随机产生一种肉类
            else if (this.profession === 'HERDSMAN') {
                const randomMeat = profession.materials[Math.floor(Math.random() * profession.materials.length)];
                this.addToInventory(randomMeat, 1 + Math.floor(Math.random() * 2));
            }
            // 果农类职业（随机）：随机产生一种水果
            else if (this.profession === 'FRUIT_GROWER') {
                const randomFruit = profession.materials[Math.floor(Math.random() * profession.materials.length)];
                this.addToInventory(randomFruit, 2 + Math.floor(Math.random() * 3));
            }
            // 伐木工类职业（非随机）：根据工作地点产生产品
            else if (this.profession === 'LUMBERJACK') {
                const randomWood = profession.materials[Math.floor(Math.random() * profession.materials.length)];
                this.addToInventory(randomWood, 1 + Math.floor(Math.random() * 2));
            }
            // 其他生产类职业
            else {
                const randomMaterial = profession.materials[Math.floor(Math.random() * profession.materials.length)];
                const quantity = this.profession === 'FARMER' ? 2 + Math.floor(Math.random() * 4) : 1;
                this.addToInventory(randomMaterial, quantity);
            }
        }
        
        // 特殊职业处理
        switch (this.profession) {
            case 'WATER_CARRIER':
                this.addToInventory('水', 50);
                break;
        }
    }
    
    // 添加到物品栏
    addToInventory(itemName, quantity) {
        const item = ITEMS.find(i => i.name === itemName);
        if (item) {
            if (item.type === 'material' || item.type === 'food') {
                const existing = this.inventory[item.type + 's'].find(i => i.name === itemName);
                if (existing) {
                    existing.quantity += quantity;
                } else {
                    this.inventory[item.type + 's'].push({...item, quantity});
                }
            }
        }
    }
    
    // 从物品栏移除物品
    removeFromInventory(itemName, quantity) {
        const itemTypes = ['materials', 'food', 'tools'];
        for (const type of itemTypes) {
            const existing = this.inventory[type].find(i => i.name === itemName);
            if (existing) {
                existing.quantity -= quantity;
                if (existing.quantity <= 0) {
                    this.inventory[type] = this.inventory[type].filter(i => i.quantity > 0);
                }
                break;
            }
        }
    }
    
    // 消耗食物（考虑预估耗时）
    consumeFood() {
        if (this.homeStorage.food.length > 0) {
            const foodItem = this.homeStorage.food[0];
            
            // 模拟进食时间
            setTimeout(() => {
                this.needs.hunger = Math.min(100, this.needs.hunger + (foodItem.nutrition || 30));
                
                // 减少食物数量或移除
                if (foodItem.quantity > 1) {
                    foodItem.quantity--;
                } else {
                    this.homeStorage.food.shift();
                }
                
                this.currentAction = '进食完成';
            }, this.estimatedTime.eat * 1000); // 转换为毫秒
            
            this.currentAction = `进食中（剩余${this.estimatedTime.eat}分钟）`;
        } else {
            this.currentAction = '没有食物可吃';
        }
    }
    
    // 消耗水（考虑预估耗时和饮水优先级）
    consumeWater() {
        // 饮水优先级：熟水 > 泉水 > 生水
        let waterType = null;
        let waterToDrink = 0;
        
        // 检查熟水
        const cookedWater = this.homeStorage.food.find(f => f.name === '熟水');
        if (cookedWater && cookedWater.quantity > 0) {
            waterType = '熟水';
            waterToDrink = Math.min(5, cookedWater.quantity);
        }
        // 检查泉水
        else if (this.homeStorage.water > 0) {
            waterType = '泉水';
            waterToDrink = Math.min(10, this.homeStorage.water);
        }
        // 检查生水
        else {
            const rawWater = this.homeStorage.food.find(f => f.name === '生水');
            if (rawWater && rawWater.quantity > 0) {
                waterType = '生水';
                waterToDrink = Math.min(8, rawWater.quantity);
            }
        }
        
        if (waterType && waterToDrink > 0) {
            // 模拟饮水时间
            setTimeout(() => {
                // 消耗水
                if (waterType === '熟水' || waterType === '生水') {
                    const waterItem = this.homeStorage.food.find(f => f.name === waterType);
                    if (waterItem.quantity > waterToDrink) {
                        waterItem.quantity -= waterToDrink;
                    } else {
                        this.homeStorage.food = this.homeStorage.food.filter(f => f.name !== waterType);
                    }
                } else if (waterType === '泉水') {
                    this.homeStorage.water -= waterToDrink;
                }
                
                // 恢复口渴度
                this.needs.thirst = Math.min(100, this.needs.thirst + waterToDrink * 12);
                
                // 生水有25%概率导致腹泻
                if (waterType === '生水' && Math.random() < 0.25) {
                    this.triggerDiarrhea();
                } else {
                    this.currentAction = `饮用${waterType}完成`;
                }
            }, this.estimatedTime.drink * 1000);
            
            this.currentAction = `饮用${waterType}中（剩余${this.estimatedTime.drink}分钟）`;
        } else {
            this.currentAction = '没有水可喝';
        }
    }
    
    // 触发腹泻状态
    triggerDiarrhea() {
        this.diarrhea.active = true;
        this.diarrhea.duration = 1 + Math.floor(Math.random() * 6); // 1-6小时
        this.diarrhea.startTime = new Date();
        this.debuffs.diarrhea = true;
        this.currentAction = `饮用了生水导致腹泻（持续${this.diarrhea.duration}小时）`;
    }
    
    // 自动决策行为
    makeDecision(gameTime, otherCharacters) {
        const hour = gameTime.hour;
        
        // 检查是否需要睡觉（精力低于阈值）
        if (this.needs.energy < this.needsThreshold.energy * 100) {
            if (this.currentLocation !== '城镇广场') {
                this.moveTo('城镇广场');
                this.currentAction = '回家睡觉';
                return;
            }
            this.currentAction = `睡觉中（预计${this.estimatedTime.sleep}分钟）`;
            return;
        }
        
        // 检查是否需要喝水（口渴低于阈值）
        if (this.needs.thirst < this.needsThreshold.thirst * 100) {
            this.currentAction = `饮水（预计${this.estimatedTime.drink}分钟）`;
            this.consumeWater();
            return;
        }
        
        // 检查是否需要吃饭（饥饿低于阈值）
        if (this.needs.hunger < this.needsThreshold.hunger * 100) {
            this.currentAction = `进食（预计${this.estimatedTime.eat}分钟）`;
            this.consumeFood();
            return;
        }
        
        // 购物时间（18:00-19:00）- 购买食物和水
        if (hour === 18 && this.currentLocation === '城镇广场') {
            this.buySupplies();
            return;
        }
        
        // 固定吃饭时间（补充）
        if (hour === this.dailySchedule.lunchTime && this.needs.hunger < 70) {
            this.currentAction = `午餐时间（预计${this.estimatedTime.eat}分钟）`;
            this.consumeFood();
            return;
        }
        
        // 工作时间
        if (hour >= this.dailySchedule.workStartTime && hour < this.dailySchedule.workEndTime) {
            if (!this.isWorking && !this.isMoving) {
                // 挑水工特殊逻辑
                if (this.profession === 'WATER_CARRIER') {
                    this.waterCarrierWork();
                    return;
                }
                
                // 检查是否需要购买原材料
                if (this.needsMaterials()) {
                    this.findAndBuyMaterials(otherCharacters);
                } else {
                    this.startWork();
                }
            }
            return;
        }
        
        // 其他时间自由活动
        if (!this.isMoving && Math.random() < 0.3) {
            const randomLocations = ['城镇广场', '河滨', '森林'];
            const randomLocation = randomLocations[Math.floor(Math.random() * randomLocations.length)];
            if (this.currentLocation !== randomLocation) {
                this.moveTo(randomLocation);
            }
        }
    }
    
    // 购买补给品
    buySupplies() {
        // 购买食物
        const foodToBuy = ['炖牛肉', '炖鱼', '面包', '苹果'];
        const selectedFood = foodToBuy[Math.floor(Math.random() * foodToBuy.length)];
        const foodItem = ITEMS.find(item => item.name === selectedFood);
        
        if (foodItem && this.inventory.money >= foodItem.price) {
            this.inventory.money -= foodItem.price;
            this.homeStorage.food.push({...foodItem, quantity: 1});
            this.currentAction = `购买了${selectedFood}`;
        }
        
        // 购买水
        const waterPrice = 2;
        const waterToBuy = Math.min(10, Math.floor(this.inventory.money / waterPrice));
        if (waterToBuy > 0) {
            this.inventory.money -= waterToBuy * waterPrice;
            this.homeStorage.water += waterToBuy;
            this.currentAction += waterToBuy > 0 ? `，购买了${waterToBuy}单位水` : '';
        }
    }
    
    // 检查是否需要原材料（根据职业定义）
    needsMaterials() {
        const profession = PROFESSIONS[this.profession];
        
        if (!profession.materials || profession.materials.length === 0) {
            return false;
        }
        
        // 厨师需要食材
        if (this.profession === 'CHEF') {
            return !this.inventory.materials.some(mat => ['鲜鱼', '牛肉', '小麦'].includes(mat.name));
        }
        // 铁匠需要矿石
        else if (this.profession === 'BLACKSMITH') {
            return !this.inventory.materials.some(mat => ['铁矿石', '铜矿石'].includes(mat.name));
        }
        // 其他生产职业不需要购买原材料
        else {
            return false;
        }
    }
    
    // 寻找并购买原材料
    findAndBuyMaterials(otherCharacters) {
        // 简化实现：直接移动到相关地点
        if (this.profession === 'CHEF') {
            this.moveTo('河滨');
            this.currentAction = '前往购买食材';
        } else if (this.profession === 'BLACKSMITH') {
            this.moveTo('铁矿山');
            this.currentAction = '前往购买矿石';
        }
    }
    
    // 挑水工工作逻辑
    waterCarrierWork() {
        if (this.currentLocation === '河滨') {
            // 在河滨取水
            this.addToInventory('水', 50);
            this.moveTo('城镇广场');
            this.currentAction = '取水完成，返回城镇';
        } else if (this.currentLocation === '城镇广场' && this.inventory.materials.some(mat => mat.name === '水')) {
            // 在城镇广场倒水到水井
            const waterItem = this.inventory.materials.find(mat => mat.name === '水');
            if (waterItem) {
                waterItem.quantity = 0;
                this.inventory.materials = this.inventory.materials.filter(mat => mat.quantity > 0);
                this.currentAction = '已将水倒入水井';
                setTimeout(() => {
                    this.moveTo('河滨');
                    this.currentAction = '前往河滨取水';
                }, 2000);
            }
        } else {
            this.moveTo('河滨');
            this.currentAction = '前往河滨取水';
        }
    }
}

